<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Metadata</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mysqli.quickstart.transactions.html">« API support for transactions</a></li>
      <li style="float: right;"><a href="mysqli.setup.html">安装/配置 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mysqli.quickstart.html">Quick start guide</a></li>
    <li>Metadata</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqli.quickstart.metadata" class="section">
  <h2 class="title">Metadata</h2>
  <p class="para">
   A MySQL result set contains metadata. The metadata describes the columns
   found in the result set. All metadata sent by MySQL is accessible
   through the <code class="literal">mysqli</code> interface.
   The extension performs no or negligible changes to the
   information it receives.
   Differences between MySQL server versions are not aligned.
  </p>
  <p class="para">
   Meta data is access through the <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> interface.
  </p>
  <p class="para">
   <div class="example" id="example-1437">
    <p><strong>示例 #1 Accessing result set meta data</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"example.com"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1&nbsp;AS&nbsp;_one,&nbsp;'Hello'&nbsp;AS&nbsp;_two&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_fields</span><span style="color: #007700">());</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(2) {
  [0]=&gt;
  object(stdClass)#3 (13) {
    [&quot;name&quot;]=&gt;
    string(4) &quot;_one&quot;
    [&quot;orgname&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;table&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;orgtable&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;def&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;db&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;catalog&quot;]=&gt;
    string(3) &quot;def&quot;
    [&quot;max_length&quot;]=&gt;
    int(1)
    [&quot;length&quot;]=&gt;
    int(1)
    [&quot;charsetnr&quot;]=&gt;
    int(63)
    [&quot;flags&quot;]=&gt;
    int(32897)
    [&quot;type&quot;]=&gt;
    int(8)
    [&quot;decimals&quot;]=&gt;
    int(0)
  }
  [1]=&gt;
  object(stdClass)#4 (13) {
    [&quot;name&quot;]=&gt;
    string(4) &quot;_two&quot;
    [&quot;orgname&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;table&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;orgtable&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;def&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;db&quot;]=&gt;
    string(0) &quot;&quot;
    [&quot;catalog&quot;]=&gt;
    string(3) &quot;def&quot;
    [&quot;max_length&quot;]=&gt;
    int(5)
    [&quot;length&quot;]=&gt;
    int(5)
    [&quot;charsetnr&quot;]=&gt;
    int(8)
    [&quot;flags&quot;]=&gt;
    int(1)
    [&quot;type&quot;]=&gt;
    int(253)
    [&quot;decimals&quot;]=&gt;
    int(31)
  }
}
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <em class="emphasis">Prepared statements</em>
  </p>
  <p class="para">
   Meta data of result sets created using prepared statements are accessed
   the same way. A suitable <span class="classname"><a href="class.mysqli-result.html" class="classname">mysqli_result</a></span> handle is
   returned by <span class="methodname"><a href="mysqli-stmt.result-metadata.html" class="methodname">mysqli_stmt::result_metadata()</a></span>.
  </p>
  <p class="para">
   <div class="example" id="example-1438">
    <p><strong>示例 #2 Prepared statements metadata</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"example.com"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;1&nbsp;AS&nbsp;_one,&nbsp;'Hello'&nbsp;AS&nbsp;_two&nbsp;FROM&nbsp;DUAL"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">result_metadata</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_fields</span><span style="color: #007700">());</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <em class="emphasis">See also</em>
  </p>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="mysqli.query.html" class="methodname">mysqli::query()</a></span></li>
    <li class="member"><span class="methodname"><a href="mysqli-result.fetch-fields.html" class="methodname">mysqli_result::fetch_fields()</a></span></li>
   </ul>
  </p>
 </div></div></div></body></html>